home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / modex104.zip / X-DEMO.C < prev    next >
C/C++ Source or Header  |  1993-05-14  |  15KB  |  781 lines

  1. /* X-DEMO.C - a Mode "X" Demo      */
  2. /* By Matt Pritchard, 14 Apr, 1993 */
  3.  
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6.  
  7. #include "modex.h"
  8. #include "c_utils.h"
  9.  
  10. #define MAX_SHAPES  32
  11. #define MAX_SPRITES 64
  12.  
  13.     /* routines in this file */
  14.  
  15. void demo_res (int, int, int);
  16. int  get_key (void);
  17. void error_out (char*);
  18. void load_shapes (void);
  19. int  int_sqrt (int, int);
  20. void page_demo (void);
  21.  
  22.     /* Structures for Sprites */
  23.  
  24. struct Shape
  25. {
  26.     unsigned char Image[512];
  27.     int           X_Width;
  28.     int              Y_Width;
  29. }   Img [MAX_SHAPES];
  30.  
  31. struct Sprite
  32. {
  33.     int    X_pos;
  34.     int    Y_pos;
  35.     int X_Dir;
  36.     int Y_Dir;
  37.     int    Shape;
  38.     int    Last_X [2];
  39.     int Last_Y [2];
  40. }   Obj [MAX_SPRITES];
  41.  
  42.  
  43.     /* MAIN */
  44.  
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48.  
  49.    /*    if (argc > 0)
  50.     {
  51.         while (argc > 0)
  52.         {
  53.             dos_print ("Unknown Argument: ");
  54.             dos_print (makefp argv[argc]);
  55.             argc--;
  56.         }
  57.         return (0);
  58.  
  59.     }
  60.      */
  61.  
  62.     init_random ();
  63.  
  64.     load_shapes ();
  65.  
  66.     demo_res ( Mode_320x200, 320, 200 );
  67.     demo_res ( Mode_320x400, 320, 400 );
  68.  
  69.     demo_res ( Mode_360x200, 360, 200 );
  70.     demo_res ( Mode_360x400, 360, 400 );
  71.  
  72.     demo_res ( Mode_320x240, 320, 240 );
  73.     demo_res ( Mode_320x480, 320, 480 );
  74.  
  75.     demo_res ( Mode_360x240, 360, 240 );
  76.     demo_res ( Mode_360x480, 360, 480 );
  77.  
  78.     page_demo ();
  79.  
  80.     set_video_mode (3);
  81.     dos_print ("This Mode X Demo is Finished");
  82.     return (0);
  83.  
  84. }
  85.  
  86.  
  87.     /* Demonstrate a given resolution */
  88.  
  89.  
  90. void demo_res (int Screen_Mode, int X_max, int Y_max)
  91. {
  92.  
  93. char     *Error1 = "Failure while calling SET_MODEX";
  94. char    *Error2 = "Failure during READ_PIXEL test";
  95.  
  96. char    *Abort_Msg = "Demo aborted by User";
  97.  
  98. char    *Demo_Msg = " This is a MODE X demo ";
  99. char    *Scrn_Msg = "Screen Resolution is     by    ";
  100. char    *Cont_Msg = "Press <ANY KEY> to Continue";
  101.  
  102. char    *Line_Msg = "LINE TEST";
  103. char    *Fill_Msg = "FILL TEST";
  104. char    *Pixel_Msg = "PIXEL TEST";
  105.  
  106. char    Text[10];
  107.  
  108. int        x1, y1, x2, y2 = 0;
  109. int        x, y, z = 0;
  110. int        X_Center, gap = 0;
  111.  
  112.  
  113.     if (set_modex (Screen_Mode) == 0)
  114.     {
  115.         error_out (Error1);
  116.     }
  117.  
  118.     X_Center = X_max / 2;
  119.  
  120.     x1 = 10;
  121.     y1 = 10;
  122.     x2 = X_max - 1;
  123.     y2 = Y_max - 1;
  124.  
  125.     for (z = 0; z <= 3; z++)
  126.     {
  127.         y = 31 - z -z;
  128.         draw_line (x1+z, y1+z, x2-z, y1+z, y);
  129.         draw_line (x1+z, y1+z, x1+z, y2-z, y);
  130.         draw_line (x1+z, y2-z, x2-z, y2-z, y);
  131.         draw_line (x2-z, y1+z, x2-z, y2-z, y);
  132.     }
  133.  
  134.     for (x = 0; x < (X_max / 10); x++)
  135.     {
  136.         tgprintc (48 + ((x+1) % 10), x*10+1, 1, 9 + ((x/8) % 7) );
  137.         draw_line (x*10+9, 0, x*10+9, 3, c_bWHITE);
  138.     }
  139.  
  140.     for (y = 0; y < (Y_max / 10); y++)
  141.     {
  142.         tgprintc (48 + ((y+1) % 10), 1, y*10+1, 9 + ((y/10) % 7) );
  143.         draw_line (0, y*10+9, 3, y*10+9, c_bWHITE);
  144.     }
  145.  
  146.     for (x = 0; x <= 63; x++)
  147.     {
  148.         z = 15 + (x * 3 / 4);
  149.         set_dac_register (64+x, z, z, z);
  150.         set_dac_register (128+x, 0, z, z);
  151.  
  152.         draw_line (103-x, 60, 40+x, 123, 64+x);
  153.         draw_line (40, 60+x, 103, 123-x, 128+x);
  154.  
  155.     }
  156.  
  157.     tprint_str (Line_Msg, 9, 37, 130, c_BLUE);
  158.  
  159.     y = 60;
  160.     gap = 0;
  161.     for (x = 0; x <= 9; x++)
  162.     {
  163.         fill_block (120, y, 120+x, y+gap, 64+x);
  164.         fill_block (140 - (15-x), y, 150+x, y+gap, 230+x);
  165.         fill_block (170 - (15-x), y, 170, y+gap, 128+x);
  166.         y = y + gap + 2;
  167.         gap++;
  168.     }
  169.  
  170.     tprint_str (Fill_Msg, 9, 110, 46, c_GREEN);
  171.  
  172.     for (x = 190; x <= 250; x+=2)
  173.     {
  174.         for (y = 60; y <= 122; y+=2)
  175.         {
  176.             z = (x+x+y+y) & 0xff;
  177.             set_point (x, y, z);
  178.         }
  179.     }
  180.  
  181.     tprint_str (Pixel_Msg, 10, 182, 130, c_RED);
  182.  
  183.     for (x = 190; x <= 250; x+=2)
  184.     {
  185.         for (y = 60; y <= 122; y+=2)
  186.         {
  187.             z = (x+x+y+y) & 0xff;
  188.             if (read_point(x, y) != z)
  189.             {
  190.                 error_out (Error2);
  191.             }
  192.         }
  193.     }
  194.  
  195.     print_str (Demo_Msg, 23, X_Center - 92, 20, c_bRED, c_BLUE);
  196.  
  197.     x = X_Center - 124;
  198.     print_str (Scrn_Msg, 28, x, 30, c_bGREEN, c_BLACK);
  199.  
  200.     sprintf (Text, "%3d", X_max);
  201.     print_str (Text, 3, x+168, 30, c_bPURPLE, c_BLACK);
  202.  
  203.     sprintf (Text, "%3d", Y_max);
  204.     print_str (Text, 3, x + 224, 30, c_bWHITE, c_BLACK);
  205.  
  206.     for (x = 0; x <= 15; x++)
  207.     {
  208.         set_dac_register (230+x, 63-x*4, 0, 15+x*3);
  209.         draw_line (30+x, Y_max-6-x, X_max-20-x, Y_max-6-x, 230+x);
  210.     }
  211.  
  212.     tprint_str (Cont_Msg, 27, X_Center - 103, Y_max-18, c_YELLOW);
  213.  
  214.     if (get_key () == Ky_ESC)
  215.     {
  216.         error_out (Abort_Msg);
  217.     }
  218.  
  219.     return ;
  220.  
  221. }
  222.  
  223.  
  224.     /* Wait for a Keystroke */
  225.  
  226.  
  227. int get_key(void)
  228. {
  229.  
  230. int    c = 0;
  231.  
  232.     while (c == 0)
  233.     {
  234.         c = scan_keyboard ();
  235.     }
  236.  
  237.     return (c);
  238.  
  239. }
  240.  
  241.  
  242.     /* Error Handling Routine */
  243.  
  244.  
  245. void error_out (char * text)
  246. {
  247.  
  248.     set_video_mode (3);
  249.     dos_print (text);
  250.     exit (EXIT_SUCCESS);
  251.  
  252. }
  253.  
  254.  
  255.     /* Routine to generate random sprites */
  256.  
  257.  
  258. void load_shapes ()
  259. {
  260.  
  261. unsigned char     Grid[33][33];
  262.  
  263. char    *Error1 = "Bad Shape Selected Error";
  264.  
  265. int        Shape;
  266. int        x, y, z;
  267. int        Style, Color;
  268. int        X_Width, Y_Width, Center, S_Width;
  269. int        Hollow_X, Hollow_Y;
  270.  
  271.     for (Shape = 0; Shape < MAX_SHAPES; Shape++)
  272.     {
  273.         for (y = 0; y <= 32; y++)
  274.         {
  275.             for (x = 0; x <= 32; x++)
  276.             {
  277.                 Grid[x][y] = c_BLACK;
  278.             }
  279.         }
  280.  
  281.         Style = random_int (6);
  282.         Color = 1 + random_int (15);
  283.  
  284.         switch (Style)
  285.  
  286.         {
  287.                 /* SOLID BOXES */
  288.  
  289.             case 0:
  290.  
  291.             {
  292.                 do
  293.                 {
  294.                     X_Width = 3 + random_int(30);
  295.                     Y_Width = 3 + random_int(30);
  296.  
  297.                 } while ( (X_Width * Y_Width) >= 512);
  298.  
  299.                 for (x = 1; x <= X_Width; x++)
  300.                 {
  301.                     for (y = 1; y <= Y_Width; y++)
  302.                     {
  303.                        Grid[x][y] = Color;
  304.                     }
  305.                 }
  306.  
  307.                 break;
  308.  
  309.             }
  310.                 /* HOLLOW BOXES */
  311.  
  312.             case 1:
  313.  
  314.             {
  315.                 do {
  316.                     X_Width = 6 + random_int(27);
  317.                     Y_Width = 6 + random_int(27);
  318.                 } while ( (X_Width * Y_Width) >= 512);
  319.  
  320.                 for (y = 1; y <= Y_Width; y++)
  321.                 {
  322.                     for (x = 1; x <= X_Width; x++)
  323.                     {
  324.                         Grid[x][y] = Color;
  325.                     }
  326.                 }
  327.  
  328.                 Hollow_X = 1 + random_int ((X_Width / 2) -1);
  329.                 Hollow_Y = 1 + random_int ((Y_Width / 2) -1);
  330.  
  331.                 for (y = Hollow_Y+1; y <= Y_Width-Hollow_Y; y++)
  332.                 {
  333.                     for (x = Hollow_X+1; x <= X_Width-Hollow_X; x++)
  334.                     {
  335.                         Grid[x][y] = c_BLACK;
  336.                     }
  337.                 }
  338.  
  339.                 break;
  340.  
  341.             }
  342.  
  343.                 /* SOLID DIAMOND */
  344.  
  345.             case 2:
  346.  
  347.             {
  348.  
  349.                 X_Width = 3 + 2 * random_int(10);
  350.                 Y_Width = X_Width;
  351.                 Center = X_Width / 2;
  352.  
  353.                 for (y = 0; y <= Center; y++)
  354.                 {
  355.                     for (x = 0; x <= y; x++)
  356.                     {
  357.                         Grid [Center-x+1][y+1] = Color;
  358.                         Grid [Center+x+1][y+1] = Color;
  359.                         Grid [Center-x+1][Y_Width-y] = Color;
  360.                         Grid [Center+x+1][Y_Width-y] = Color;
  361.                     }
  362.                 }
  363.  
  364.                 break;
  365.  
  366.             }
  367.  
  368.                 /* HOLLOW DIAMOND */
  369.  
  370.             case 3:
  371.  
  372.             {
  373.  
  374.                 X_Width = 3 + 2 * random_int(10);
  375.                 Y_Width = X_Width;
  376.                 Center = X_Width / 2;
  377.                 S_Width = random_int (Center);
  378.  
  379.                 for (y = 0; y <= Center; y++)
  380.                 {
  381.                     for (x = 0; x <= y; x++)
  382.                     {
  383.                         if ( x+(Center-y) >= S_Width )
  384.                         {
  385.                             Grid [Center-x+1][y+1] = Color;
  386.                             Grid [Center+x+1][y+1] = Color;
  387.                             Grid [Center-x+1][Y_Width-y] = Color;
  388.                             Grid [Center+x+1][Y_Width-y] = Color;
  389.                         }
  390.                     }
  391.                 }
  392.  
  393.                 break;
  394.  
  395.             }
  396.  
  397.                 /* BALL */
  398.  
  399.             case 4:
  400.  
  401.             {
  402.  
  403.                 X_Width = 7 + 2 * random_int (8);
  404.                 Y_Width = X_Width;
  405.                 Center  = 1 + X_Width / 2;
  406.  
  407.                 for (y = 1; y <= Y_Width; y++)
  408.                 {
  409.                     for (x = 1; x <= X_Width; x++)
  410.                     {
  411.                         z = int_sqrt(Center-x, Center-y);
  412.                         if (z < Center)
  413.                         {
  414.                             Grid[x][y] = 150 + Color * 2 + z * 3;
  415.                         }
  416.                     }
  417.                 }
  418.  
  419.                 break;
  420.             }
  421.  
  422.                 /* HOLLOW BALLS */
  423.  
  424.             case 5:
  425.  
  426.             {
  427.                 X_Width = 7 + 2 * random_int (8);
  428.                 Y_Width = X_Width;
  429.                 Center  = 1 + X_Width / 2;
  430.                 S_Width = random_int (X_Width);
  431.  
  432.                 for (y = 1; y <= Y_Width; y++)
  433.                 {
  434.                     for (x = 1; x <= X_Width; x++)
  435.                     {
  436.                         z = int_sqrt(Center-x, Center-y);
  437.                         if ( (z < Center) && (z >= S_Width) )
  438.                         {
  439.                             Grid[x][y] = 150 + Color * 2 + z * 3;
  440.                         }
  441.                     }
  442.                 }
  443.  
  444.  
  445.                 break;
  446.             }
  447.  
  448.             default:
  449.  
  450.             {
  451.                 error_out (Error1);
  452.                 break;
  453.  
  454.             }
  455.  
  456.         }
  457.  
  458.         z = 0;
  459.         for (y = 1; y <= Y_Width; y++)
  460.         {
  461.             for (x = 1; x <= X_Width; x++)
  462.             {
  463.                 Img[Shape].Image[z] = Grid[x][y];
  464.                 z++;
  465.             }
  466.         }
  467.  
  468.         Img[Shape].X_Width = X_Width;
  469.         Img[Shape].Y_Width = Y_Width;
  470.  
  471.     }
  472.  
  473.     return;
  474. }
  475.  
  476.  
  477.     /* Quickie Psuedo Integer Square Root Routine */
  478.  
  479.  
  480. int int_sqrt ( int x, int y )
  481. {
  482.  
  483. int    Sqr_Table[12] = {1, 4, 9, 6, 25, 36, 49, 64, 81, 100, 121, 144};
  484.  
  485. int    r, d;
  486.  
  487.     d = (x * x) + (y * y);
  488.     r = 0;
  489.  
  490.     while ( d >= Sqr_Table[r] )
  491.     {
  492.         r++;
  493.     }
  494.  
  495.     return (r);
  496.  
  497. }
  498.  
  499.  
  500.     /* The Bit Sprite Demo */
  501.  
  502.  
  503. void page_demo ()
  504. {
  505.  
  506. char    *Error1 = "Failure during SET_VGA_MODEX (0, 360, 240, 3) call";
  507.  
  508. int        Last_Objects[2], Visible_Objects;
  509.  
  510. int        Screen_X = 360;
  511. int        Screen_Y = 240;
  512.  
  513. int        x, y, z;
  514. int        c, dc;
  515. int        x1, y1, x2, y2;
  516.  
  517. int        Sprite_X, Sprite_Y;
  518. int        Current_Page;
  519. int        New_X, New_Y;
  520.  
  521. int        View_X,    View_Y,    View_Max, View_Cnt, View_XD, View_YD;
  522. int        Set_Color, Prev_Color, S_Dir, P_Dir;
  523.  
  524. int        Demo_Running = True;
  525. int        redo, code;
  526.  
  527.     if (set_vga_modex(Mode_320x200, Screen_X, Screen_Y, 3) == 0)
  528.     {
  529.         error_out (Error1);
  530.     }
  531.  
  532.     set_active_page (0);
  533.     clear_vga_screen (c_BLACK);
  534.  
  535.        print_str ("This is a Test of the Following Functions:", 99, 10, 9, c_bWHITE, c_BLACK);
  536.  
  537.     draw_line (10, 18, 350, 18, c_YELLOW);
  538.     print_str ("SET_ACTIVE_PAGE", 99, 10, 20, c_bBLUE, c_BLACK);
  539.     print_str ("SET_DISPLAY_PAGE", 99, 10, 30, c_GREEN, c_BLACK);
  540.     print_str ("SET_DAC_REGISTER", 99, 10, 40, c_RED, c_BLACK);
  541.     print_str ("CLEAR_VGA_SCREEN", 99, 10, 50, c_CYAN, c_BLACK);
  542.  
  543.     print_str ("TDRAW_BITMAP", 99, 10, 60, c_PURPLE, c_BLACK);
  544.     print_str ("COPY_PAGE", 99, 10, 70, c_GREEN, c_BLACK);
  545.     print_str ("COPY_BITMAP", 99, 10, 80, c_CYAN, c_BLACK);
  546.  
  547.     print_str ("GPRINTC", 99, 10, 90, c_BLUE, c_BLACK);
  548.     print_str ("TGPRINTC", 99, 10, 100, c_GREEN, c_BLACK);
  549.     print_str ("SET_WINDOW", 99, 10, 110, c_RED, c_BLACK);
  550.  
  551.     print_str ("VIRTUAL SCREEN SIZES", 20, 190, 20, c_bBLUE, c_BLACK);
  552.     print_str ("    SMOOTH SCROLLING", 20, 190, 30, c_GREEN, c_BLACK);
  553.     print_str ("    SPRITE ANIMATION", 20, 190, 40, c_CYAN, c_BLACK);
  554.     print_str ("       PAGE FLIPPING", 20, 190, 50, c_RED, c_BLACK);
  555.     print_str ("       COLOR CYCLING", 20, 190, 60, c_PURPLE, c_BLACK);
  556.  
  557.     for (x = 0; x <=60; x++)
  558.     {
  559.         set_dac_register (50 + x, 3 + x, 0, 60 - x);
  560.         set_dac_register (150 + x, 3 + x, 0, 60 - x);
  561.     }
  562.  
  563.     c = 0;
  564.     dc = 1;
  565.     for (x = 0; x <= (Screen_X / 2); x++)
  566.     {
  567.         draw_line (Screen_X / 2 - 1, Screen_Y / 4, x, Screen_Y - 1, c + 50);
  568.         draw_line (Screen_X / 2, Screen_Y / 4, Screen_X - x - 1, Screen_Y - 1, c + 50);
  569.         c+= dc;
  570.         if ((c == 0) || (c == 60) ) { dc = -dc;}
  571.     }
  572.  
  573.     tprint_str ("Press <ANY KEY> to Continue", 99, 72, 190, c_bWHITE);
  574.     tprint_str ("< > = Faster   < > = Slower", 99, 72, 204, c_bGREEN);
  575.     tprint_str ("< > = Fewer Shapes  < > = More Shapes", 99, 32, 218, c_bCYAN);
  576.  
  577.     tgprintc (43, 80, 204, c_YELLOW);
  578.     tgprintc (45, 200, 204, c_YELLOW);
  579.  
  580.     tgprintc (25, 40, 218, c_YELLOW);
  581.     tgprintc (24, 200, 218, c_YELLOW);
  582.  
  583.     copy_page (0, 1);
  584.     copy_page (0, 2);
  585.  
  586.     for (x = 0; x < MAX_SPRITES; x++)
  587.     {
  588.         do {
  589.             Obj[x].X_Dir = random_int(7) - 3;
  590.             Obj[x].Y_Dir = random_int(7) - 3;
  591.         } while ( (Obj[x].X_Dir == 0) && (Obj[x].Y_Dir == 0) );
  592.  
  593.         Obj[x].Shape = x % MAX_SHAPES;
  594.  
  595.         Sprite_X = Img[Obj[x].Shape].X_Width;
  596.         Sprite_Y = Img[Obj[x].Shape].Y_Width;
  597.  
  598.         Obj[x].X_pos = 1 + random_int(Screen_X - Sprite_X - 2);
  599.         Obj[x].Y_pos = 1 + random_int(Screen_Y - Sprite_Y - 2);
  600.  
  601.         Obj[x].Last_X[0] = Obj[x].X_pos;
  602.         Obj[x].Last_X[1] = Obj[x].X_pos;
  603.         Obj[x].Last_Y[0] = Obj[x].Y_pos;
  604.         Obj[x].Last_Y[1] = Obj[x].Y_pos;
  605.  
  606.     }
  607.  
  608.     Current_Page = 0;
  609.  
  610.     View_X = 0;
  611.     View_Y = 0;
  612.     View_Max = 3;
  613.     View_Cnt = 0;
  614.     View_XD = 1;
  615.     View_YD = 1;
  616.  
  617.     Set_Color = 3;
  618.     S_Dir = 1;
  619.     Prev_Color = 0;
  620.     P_Dir = 1;
  621.  
  622.     Visible_Objects = MAX_SPRITES / 2;
  623.     Last_Objects[0] = 0;
  624.     Last_Objects[1] = 0;
  625.  
  626.     while (Demo_Running)
  627.     {
  628.  
  629.         set_active_page (Current_Page);
  630.  
  631.             /* Erase Old Images */
  632.  
  633.         for (x = 0; x <= Last_Objects[Current_Page]; x++)
  634.         {
  635.             z = 2;
  636.             y = Obj[x].Shape;
  637.             x1 = Obj[x].Last_X[Current_Page];
  638.             y1 = Obj[x].Last_Y[Current_Page];
  639.             x2 = x1 + Img[y].X_Width -1;
  640.             y2 = y1 + Img[y].Y_Width -1;
  641.  
  642.             x1 = x1 & 0xfffc;
  643.             x2 = x2 | 0x0003;
  644.  
  645.             copy_bitmap (z, x1, y1, x2, y2, Current_Page, x1, y1);
  646.         }
  647.  
  648.             /* Draw new images */
  649.  
  650.         for (x = 0; x <= Visible_Objects; x++)
  651.         {
  652.             Sprite_X = Img[Obj[x].Shape].X_Width;
  653.             Sprite_Y = Img[Obj[x].Shape].Y_Width;
  654.  
  655.             /*  Move Sprite */
  656.  
  657.             do
  658.             {
  659.                 redo = False;
  660.                 New_X = Obj[x].X_pos + Obj[x].X_Dir;
  661.  
  662.                 if (( New_X < 0 ) || (New_X + Sprite_X > Screen_X) )
  663.                 {
  664.                     Obj[x].X_Dir = -Obj[x].X_Dir;
  665.                     if (random_int(20) == 1)
  666.                     {
  667.                         do
  668.                         {
  669.                             Obj[x].X_Dir = random_int(7) - 3;
  670.                             Obj[x].Y_Dir = random_int(7) - 3;
  671.                         } while ( (Obj[x].X_Dir == 0) && (Obj[x].Y_Dir == 0) );
  672.                         redo = True;
  673.                     }
  674.                 }
  675.             } while (redo);
  676.             Obj[x].X_pos = Obj[x].X_pos + Obj[x].X_Dir;
  677.  
  678.  
  679.             do
  680.             {
  681.                 redo = False;
  682.                 New_Y = Obj[x].Y_pos + Obj[x].Y_Dir;
  683.  
  684.                 if ( (New_Y < 0) || (New_Y + Sprite_Y > Screen_Y) )
  685.                 {
  686.                     Obj[x].Y_Dir = -Obj[x].Y_Dir;
  687.                     if (random_int(20) == 1)
  688.                     {
  689.                         do
  690.                         {
  691.                             Obj[x].X_Dir = random_int(7) - 3;
  692.                             Obj[x].Y_Dir = random_int(7) - 3;
  693.                         } while ( (Obj[x].X_Dir == 0) && (Obj[x].Y_Dir == 0) );
  694.                         redo = True;
  695.                     }
  696.                 }
  697.             } while (redo);
  698.  
  699.             Obj[x].Y_pos = Obj[x].Y_pos + Obj[x].Y_Dir;
  700.  
  701.             /* Draw Sprite */
  702.  
  703.             tdraw_bitmap ((char far*) &Img[Obj[x].Shape], Obj[x].X_pos, Obj[x].Y_pos, Sprite_X, Sprite_Y);
  704.  
  705.             Obj[x].Last_X[Current_Page] = Obj[x].X_pos;
  706.             Obj[x].Last_Y[Current_Page] = Obj[x].Y_pos;
  707.  
  708.         }
  709.  
  710.         Last_Objects[Current_Page] = Visible_Objects;
  711.  
  712.  
  713.         /* Pan Screen Back & Forth */
  714.  
  715.         View_Cnt++;
  716.         if (View_Cnt >= View_Max)
  717.         {
  718.             View_X+= View_XD;
  719.             if ( (View_X == 0) || (View_X == 39) ) {View_XD = -View_XD;}
  720.             if (View_XD < 0)
  721.             {
  722.                 View_Y+= View_YD;
  723.                 if ( (View_Y == 0) || (View_Y == 39) ) {View_YD = -View_YD;}
  724.             }
  725.  
  726.             set_window (Current_Page, View_X, View_Y);
  727.  
  728.             View_Cnt = 0;
  729.         }
  730.         else
  731.         {
  732.             set_display_page (Current_Page);
  733.         }
  734.  
  735.         /* Cycle Colors */
  736.  
  737.         set_dac_register (50 + Prev_Color, 3 + Prev_Color, 0, 60 - Prev_Color);
  738.         set_dac_register (50 + Set_Color, Set_Color, 10, 63 - Set_Color);
  739.  
  740.         set_dac_register (150 + Prev_Color, 3 + Prev_Color, 0, 60 - Prev_Color);
  741.         set_dac_register (150 + Set_Color, 63, 63, Set_Color);
  742.  
  743.         Set_Color+= S_Dir;
  744.         if ( (Set_Color == 60) || (Set_Color == 0) ) {S_Dir = -S_Dir;}
  745.  
  746.         Prev_Color+= P_Dir;
  747.         if ( (Prev_Color == 60) || (Prev_Color == 0) ) {P_Dir = -P_Dir;}
  748.  
  749.         /* Check for Keystroke */
  750.  
  751.         Current_Page = Current_Page ^ 0x01;
  752.  
  753.         code = scan_keyboard ();
  754.  
  755.         if (code == Ky_ESC) {Demo_Running = False;}
  756.  
  757.         if (code == Ky_Plus)
  758.         {
  759.             if (View_Max < 12) {View_Max++;}
  760.         }
  761.  
  762.         if (code == Ky_Minus)
  763.         {
  764.             if (View_Max > 1) {View_Max--;}
  765.             if (View_Cnt >= View_Max) {View_Cnt = 0;}
  766.         }
  767.  
  768.         if (code == Ky_Up)
  769.         {
  770.             if (Visible_Objects < MAX_SPRITES-1) {Visible_Objects++;}
  771.         }
  772.  
  773.         if (code == Ky_Down)
  774.         {
  775.             if (Visible_Objects > 0) {Visible_Objects--;}
  776.         }
  777.  
  778.     }
  779.  
  780. }
  781.